package com.deft.design.responsibility.impl;

import com.deft.design.responsibility.AuthInfo;
import com.deft.design.responsibility.AuthLink;
import com.deft.design.responsibility.AuthService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author Hide丶love
 * @date 2022/05/11
 **/
public class Level3AuthLink extends AuthLink {

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime beginTime = LocalDateTime.parse("2022-06-01 10:00:00", df);
    LocalDateTime endTime = LocalDateTime.parse("2022-06-25 10:00:00", df);

    public Level3AuthLink(String levelUserId, String levelUserName) {
        super(levelUserId, levelUserName);
    }

    @Override
    public AuthInfo doAuth(String uId, String orderId, LocalDateTime authDate) {
        LocalDateTime date = AuthService.authService(levelUserId, orderId);
        if (null == date) {
            return new AuthInfo("0001", "单号：", orderId, " 状态：待三级审批负责人 ", levelUserName);
        }
        AuthLink next = super.next();
        if (null == next) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：三级审批负责人完成", " 时间：", date.toString(), " 审批人：", levelUserName);
        }

        if (authDate.isBefore(beginTime) || authDate.isAfter(endTime)) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：三级审批负责人完成", " 时间：", date.toString(), " 审批人：", levelUserName);
        }

        return next().doAuth(uId, orderId, authDate);
    }
}
